package h_10_26;

/**
 * 1208. 尽可能使字符串相等
 * https://leetcode.cn/problems/get-equal-substrings-within-budget/description/
 */
public class Main1 {
    public int equalSubstring(String s, String t, int maxCost) {
        char[] ss = s.toCharArray();
        char[] tt = t.toCharArray();
        int n = ss.length;
        int l = 0;
        int r = 0;
        int cost = 0;
        int ret = 0;
        while(r < n) {
            // 入
            cost += (Math.abs(ss[r] - tt[r]));

            // 出
            while(cost > maxCost) {
                cost -= (Math.abs(ss[l] - tt[l]));
                l++;
            }

            // 更
            ret = Math.max(ret,r - l + 1);
            r++;
        }
        return ret;
    }
}
